package windbell.domain.common;

import edu.fudan.mylang.pf.IObjectFactory;
import edu.fudan.mylang.pf.query.IQueryCriteria;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import windbell.domain.common.IContextAwareObjectInitService;

@Service
@SuppressWarnings("all")
public class ContextAwareEntities {
  @Autowired
  private IObjectFactory entities;
  
  @Autowired
  private Collection<IContextAwareObjectInitService> objectInitServices;
  
  public <S extends Object, T extends IQueryCriteria<S>> T createContextAwareQueryCriteria(final Class<T> c) {
    T _createQueryCriteria = this.entities.createQueryCriteria(c);
    final Procedure1<T> _function = new Procedure1<T>() {
        public void apply(final T criteria) {
          final Function1<IContextAwareObjectInitService,Boolean> _function = new Function1<IContextAwareObjectInitService,Boolean>() {
              public Boolean apply(final IContextAwareObjectInitService it) {
                boolean _isMyContextAwareObject = it.isMyContextAwareObject(criteria);
                return Boolean.valueOf(_isMyContextAwareObject);
              }
            };
          IContextAwareObjectInitService _findFirst = IterableExtensions.<IContextAwareObjectInitService>findFirst(ContextAwareEntities.this.objectInitServices, _function);
          if (_findFirst!=null) _findFirst.initContext(criteria);
        }
      };
    T _doubleArrow = ObjectExtensions.<T>operator_doubleArrow(_createQueryCriteria, _function);
    return _doubleArrow;
  }
}
